﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace KWSResourceBooking.KWSResourceCalendar
{
    [ToolboxItemAttribute(false)]
    public class KWSResourceCalendar : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/KWSResourceBooking/KWSResourceCalendar/KWSResourceCalendarUserControl.ascx";

        [WebBrowsable(true)]
        [WebDisplayName("Resource List Title")]
        [WebDescription("Title of the list that contains the resources.")]
        [Personalizable(PersonalizationScope.Shared)]
        [Category("KWS Configuration")]
        [DefaultValue("KWS Resources")]
        public string ResourceListTitle
        {
            get;
            set;
        }

        [WebBrowsable(true)]
        [WebDisplayName("Resource Booking List Title")]
        [WebDescription("Title of the list that contains the resource bookings.")]
        [Personalizable(PersonalizationScope.Shared)]
        [Category("KWS Configuration")]
        [DefaultValue("KWS Bookings")]
        public string ResourceBookingListTitle
        {
            get;
            set;
        }

        protected override void CreateChildControls()
        {
            //Control control = Page.LoadControl(_ascxPath);
            //Controls.Add(control);

            KWSResourceCalendarUserControl control = Page.LoadControl(_ascxPath) as KWSResourceCalendarUserControl;

            if(control != null)
            {
                control.WebPart = this;
            } 
            Controls.Add(control);
        }
    }
}
